package com.palm.core.util.castor;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ListCastor implements Castor<List> {
    public static final ListCastor instance=new ListCastor();
    @Override
    public List cast(Object v) {
        if(v==null){
            return new ArrayList(0);
        }
        if(v instanceof List){
            return (List)v;
        }
        if(v instanceof CharSequence){
            String str=v.toString();
            if(str.startsWith("[")){
                return JSON.parseArray(str);//// JsonKit.parse(str,ArrayList.class);//JSON.parseArray(str);
            }else{
                return Arrays.asList(str.split(","));
            }
        }
        return new ArrayList(0);
    }
}
